from flask_login import login_required

from ..base import base
from ..service.UploadService import *
from flask import request, jsonify
from flask_cors import cross_origin

from exts import success


@base.route('/api/file/upload', methods=['POST'])
@cross_origin(methods=['POST'])
def file_upload_api():
    '''
    文件上传 web pc端
    :return:
    '''
    file = request.files.get('file')
    if not file:
        return jsonify({'error': 'No file provided'}), 400
    file_url = upload_to_oss(file)
    return success(file_url)
